home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / CUCD / Programming / ModemLink / Source / ModemLinkDevAPI.c < prev    next >
C/C++ Source or Header  |  1997-10-24  |  3KB  |  126 lines

  1. /*
  2. ** NAME: ModemLinkDevAPI.c
  3. ** DESC: This file contains the two basic parts to any device, BeginIO and
  4. **       AbortIO.  These get linked into both the device and linked lib
  5. **       verisons.
  6. **
  7. ** AUTHOR:        DATE:       DESCRIPTION:
  8. ** ~~~~~~~~~~~~~~ ~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. ** Mike Veroukis  23 Mar 1997 Created
  10. */
  11.  
  12.  
  13. #include <exec/errors.h>
  14. #include <exec/io.h>
  15. #include <exec/ports.h>
  16. #include <exec/nodes.h>
  17. #include <dos/dos.h>
  18.  
  19. #include <proto/exec.h>
  20.  
  21. #include <stdio.h>
  22.  
  23. #include "ModemLinkAPI.h"
  24. #include "Link.h"
  25.  
  26. void __saveds __asm ML_BeginIO(register __a1 struct IORequest *IOReq)
  27. {
  28.   struct IOExtLink *LinkIO;
  29.   struct MsgPort *LinkPort;
  30.  
  31.   if (LinkIO = (struct IOExtLink *)IOReq) {
  32.     IOReq->io_Flags &= ~IOF_QUICK;
  33.     IOReq->io_Error = LinkErr_OK;
  34.  
  35.     switch (IOReq->io_Command) {
  36.       case CMD_READ:
  37.       case MLCMD_READ:
  38.         Forbid();
  39.  
  40.         LinkIO->Flags = (LinkIO->Flags & ~ML_PIPE2) | ML_PIPE0;
  41.         if (LinkPort = FindPort(LinkIO->LinkPortName))
  42.           PutMsg(LinkPort, (struct Message *)LinkIO);
  43.         else {
  44.           IOReq->io_Error = LinkErr_NOPROC;
  45.           ML_ReplyMsg(LinkIO);
  46.         }
  47.  
  48.         Permit();
  49.  
  50.         break;
  51.       case CMD_WRITE:
  52.       case MLCMD_WRITE:
  53.         Forbid();
  54.  
  55.         LinkIO->Flags = (LinkIO->Flags & ~ML_PIPE2) | ML_PIPE0;
  56.         if (LinkPort = FindPort(LinkIO->LinkPortName))
  57.           PutMsg(LinkPort, (struct Message *)LinkIO);
  58.         else {
  59.           IOReq->io_Error = LinkErr_NOPROC;
  60.           ML_ReplyMsg(LinkIO);
  61.         }
  62.  
  63.         Permit();
  64.  
  65.         break;
  66.       case CMD_CLEAR:
  67.         Forbid();
  68.  
  69.         if (FindTask(LinkIO->LinkProcName))
  70.           Signal(FindTask(LinkIO->LinkProcName), SIGBREAKF_CTRL_E);
  71.         else
  72.           IOReq->io_Error = LinkErr_NOPROC;
  73.  
  74.         Permit();
  75.         ML_ReplyMsg(LinkIO);
  76.         break;
  77.       case MLCMD_QUERY:
  78.         if (!FindPort(LinkIO->LinkPortName))
  79.           IOReq->io_Error = LinkErr_NOPROC;
  80.         else
  81.           IOReq->io_Error = LinkErr_OK;
  82.  
  83.         ML_ReplyMsg(LinkIO);
  84.         break;
  85.       case MLCMD_INIT:
  86.         Forbid();
  87.  
  88.         if (LinkPort = FindPort(LinkIO->LinkPortName))
  89.           PutMsg(LinkPort, (struct Message *)LinkIO);
  90.         else {
  91.           IOReq->io_Error = LinkErr_NOPROC;
  92.           ML_ReplyMsg(LinkIO);
  93.         }
  94.  
  95.         Permit();
  96.  
  97.         break;
  98.     }
  99.   }
  100. }
  101.  
  102. void __saveds __asm ML_AbortIO(register __a1 struct IORequest *IOReq)
  103. {
  104.   struct IOExtLink *LinkIO;
  105.   struct Task *LinkProc;
  106.  
  107.   if (LinkIO = (struct IOExtLink *)IOReq) {
  108.     IOReq->io_Error = IOERR_ABORTED;
  109.  
  110.     Forbid();
  111.  
  112.     if ((LinkIO->Flags & ML_PIPE2) == ML_PIPE0) {
  113.       Remove((struct Node *)LinkIO);
  114.       ML_ReplyMsg(LinkIO);
  115.     }
  116.  
  117.     if (LinkProc = FindTask(LinkIO->LinkProcName))
  118.       Signal(LinkProc, SIGBREAKF_CTRL_D);
  119.     else
  120.       ML_ReplyMsg(LinkIO);
  121.  
  122.     Permit();
  123.  
  124.   }
  125. }
  126.